package com.itkeien.streamprogramproject.simpStream;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;

public class SimpleStream <T>{

    private Collection<T> collection;
    SimpleStream(Collection<T> collection){
        this.collection=collection;
    }
    SimpleStream(){

    }


    private SimpleStream<T> filter(Predicate<T> predicate){

        List<T> resultList = new ArrayList<>();

        for(T t: collection){
            if(predicate.test(t)){
                resultList.add(t);
            }
        };
        return new SimpleStream<>(resultList);
    }

    private <U> SimpleStream<U> map(Function<T,U> simpleFunction){

        List<U> resultList = new ArrayList<>();
        for(T t: collection){
            U apply = simpleFunction.apply(t);
            resultList.add(apply);
        };
        return new SimpleStream<>(resultList);
    }

    private void forEach(Consumer<T> tConsumer){
        for(T t: collection){
            tConsumer.accept(t);
        };
    }

    public static <T> SimpleStream<T> of(Collection<T> list){
        SimpleStream<T> simpleStream = new SimpleStream<>(list);
        return simpleStream;
    }


    public static void main(String[] args) {
        List<Integer> list = List.of(1, 2, 3, 4,2,1);
        HashSet<Object> collect = list.stream().collect(HashSet::new, HashSet::add, HashSet::addAll);

        System.out.println(collect);
//        SimpleStream<String> simpleStream = new SimpleStream<>();
//        simpleStream.of(list)
//                .filter(
//                        x->(x&1)==1
//                )
//                .map(
//                        x->x*x
//                )
//                .forEach(
//                        (Integer i) -> System.out.println(i)
//                );
    }
}
